<?php
namespace app\restaurant\model;

use app\BaseModel;
use think\facade\Db;

class Evaluate extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_restaurant_evaluate';


    /**
     * @author chenniang
     * @DataTime: 2021-03-03 10:29
     * @功能说明:转换图片格式
     */
    public function getImgsAttr($value,$data){

        if(!empty($value)){

            return explode(',',$value);
        }

    }

    /**
     * @author chenniang
     * @DataTime: 2021-03-03 15:15
     * @功能说明:
     */
    public function getCreateTimeAttr($value,$data){

        if(!empty($value)){

            return date('Y-m-d H:i:s',$value);
        }

    }

    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis,$page){

        $data = $this->where($dis)->order('id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:43
     * @功能说明:
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2021-03-02 16:43
     * @功能说明:后端评价列表
     */
    public function adminList($dis,$page = 10){

        $data = $this->alias('a')
                ->join('longbing_card_user b','a.user_id = b.id')
                ->where($dis)
                ->group('a.id')
                ->field('a.*,b.nickName,b.avatarUrl')
                ->paginate($page)
                ->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-03-02 16:53
     * @功能说明:评价详情
     */
    public function adminInfo($dis){

        $data = $this->alias('a')
            ->join('longbing_card_user b','a.user_id = b.id')
            ->where($dis)
            ->group('a.id')
            ->field('a.*,b.nickName,b.avatarUrl')
            ->find();

        return !empty($data)?$data->toArray():[];
    }










}